<?php  echo $html->script(array("fckeditor"));?>
<?php $this->Html->addCrumb('Product Listings','/products'); ?>
<?php $this->Html->addCrumb('Sell Similar Item'); ?>
<?php if ($user_chk!=0):?>
<div id="result">
<?php echo $this->Session->flash(); ?>
<div class="products form">
<div class="search-title">Sell similar Item "<?php echo $this->data['Product']['products_title'];?>"</div>
<br />
<?php 
echo $this->Form->create('Product',array('type' => 'file'));?>
<?php
	echo $this->Form->input('pid',array('type'=>'hidden','value'=>$this->data['Product']['id']));
	echo $this->Form->input('user_id',array('type'=>'hidden','value'=>$session->read('Auth.User.id')));
?>
<input type="hidden" id="hiddencatid" value="<?php echo $this->data['Product']['category_id'];?>"/>
<div class="search-title">1. Create a descriptive title for your item</div>
<fieldset class="creat-product">
	<em>*</em>
	<?php	
		echo $this->Form->input('products_title',array('label'=>false,'div'=>false,'title'=>'Create a descriptive title for your item','class'=>'required','size'=>'104'));
	?>	
</fieldset>

<div class="select-category">	
<div class="search-title">2. Select Category </div>	
	<div class="breadcrumb"><?php echo $this->data['bredcrumb'];?></div>	
	<fieldset>
	<div class="selectcatstyle firstlabel hideContent"></div>
	<div class="selectcatstyle secondlabel hideContent"></div>
	<div class="selectcatstyle thirdlabel hideContent"></div>
	<div class="selectcatstyle fourthlabel hideContent"></div>
	</fieldset>
</div>	
<div class="select-category">
	<div class="search-title">3. Bring your item to life with pictures</div>
        <p>We require certain photos for authenticity verification.  You can also include other photos to help your item stand out to Buyers and bring it to life!</p>
	<div class="photo-upload-left">            
		All images should be a jpg, png, gif or jpeg and be under 1mb in size<br />
		<div id="addanotherimage">
		
		</div>
	</div>
	<div class="photo-upload-right">
		<fieldset><strong>Gallery Image</strong><em>*</em><?php echo $this->Form->input('fileName',array('type'=>'file',"class"=>"required validatefiletype",'label'=>false,'div'=>false));?></fieldset>
	</div>	
</div>
<div class="select-category">
	<div class="search-title">4. Describe your item specifications</div>
	<div class="select-item-info">
		<fieldset>
			<label>Global Brands<em>*</em></label>		
			<div class="GlobalBrands1">
<?php
echo $this->Form->input('Product.sugestbrands',array("div"=>false,"label"=>false,"id"=>"autobrand",'maxlength'=>false,'class'=>'required','value'=>$this->data['Brand']['brand_description']));
echo $this->Form->hidden('Product.global_brands',array("div"=>false,"label"=>false,"id"=>"autoComplete1"));
?>
</div>
		</fieldset>
		<fieldset>
			<label>Global Styles<em>*</em></label>				
			<div class="GlobalStyles1">
<?php
echo $this->Form->input('Product.sugeststyles',array("div"=>false,"label"=>false,"id"=>"autostyle",'maxlength'=>false,'class'=>'required','value'=>$this->data['ProductStyle']['brand_description']));
echo $this->Form->hidden('Product.global_styles',array("div"=>false,"label"=>false,"id"=>"autostyle1"));
?>
</div>
		</fieldset>			
		<fieldset>
			<label>Global Conditions<em>*</em></label>									
			<div class="GlobalConditions1">
        <?php
        echo $this->Form->input('Product.sugestconditions',array("div"=>false,"label"=>false,"id"=>"autocondition",'maxlength'=>false,'class'=>'required','value'=>$this->data['ProductCondition']['brand_description']));
        echo $this->Form->hidden('Product.global_conditions',array("div"=>false,"label"=>false,"id"=>"autocondition1"));
        ?>
</div>
		</fieldset>	
		<div class="AdditionalFields hideContent"></div>		
	</div>	
	<div class="item-size-info">
		<strong class="specific-item">Size Information</strong>
		<fieldset>
		<div class="Sizes hideContent"></div>		
		</fieldset>
		<br><br>If the item has damage or defects, describe them (optional)	<br>
	<?php
		echo $this->Form->input('products_damage',array('div'=>false,"label"=>false,"rows"=>8,"cols"=>53));
	?>	
	</div>	

</div>	
<div class="select-category">
	<div class="search-title">5. Describe your item</div>
        <p>Include any additional details about your item you think the Buyer might want to know.</p>
	<?php
		echo $this->Form->input('products_description',array('div'=>false,"label"=>false,"style"=>"width:766px; margin:10px 0;","class"=>"fckrequired"));
	?>
        <?php echo $fck->load('ProductProductsDescription', 'Basic');?>
	<br />Space left: <span id="counter2"></span> of 2000 characters
</div>


<div class="select-category">
	<div class="search-title">6. Specify Stock Quantity, Price &amp; Negotiation</div>
        <p>Decide whether you’d like to accept negotiation on the price or if you’d prefer a fixed price.</p>
	<fieldset class="stock-quantity">
		<table><tr><td><label>Price <em>*</em></label></td><td><?php echo $this->Form->input('products_price',array("label"=>false,"div"=>false,"class"=>"required number"));?></td><td>
		<label>Commission Fee : </label></td><td>$0.00</td><td>
		<label>&nbsp;&nbsp;&nbsp;&nbsp;Quantity <em>*</em></label></td><td><?php echo $this->Form->input('products_quantity',array("label"=>false,"div"=>false,"class"=>"required digits"));?></td>
		<!--td><label>Weight</label></td><td><?php echo $this->Form->input('products_weight',array("label"=>false,"div"=>false));?></td-->
		</tr></table>
	</fieldset>
		
	<fieldset class="stock-quantity">
		<?php	
			echo $this->Form->input('negotiable',array("div"=>false,"type"=>"checkbox","label"=>false,"checked"=>"checked","value"=>"Yes","class"=>"checkBox-position"));		
		?><label>Make this product negotiable</label>	
		<p class="sub-option">		
			<?php echo $this->Form->input('leastprice',array("div"=>false,"type"=>"checkbox","label"=>false,"class"=>"checkBox-position"));?>
			<label>Automatically accept offers of at least $</label>			
			<?php echo $this->Form->input('products_offerAcceptLeastPrice',array("div"=>false,"label"=>false,"disabled"=>"disabled","size"=>10));?>
		</p>
		<p class="sub-option">
			<?php echo $this->Form->input('lowerprice',array("div"=>false,"type"=>"checkbox","label"=>false,"class"=>"checkBox-position"));?>
			<label>Automatically decline offers lower than $</label>
			<?php echo $this->Form->input('products_offerDeclineLowerPrice',array("div"=>false,"label"=>false,"disabled"=>"disabled","size"=>10));?>
		 </p>		
	</fieldset>	
</div>

<div class="select-category">	
	<div class="search-title">7. Set shipping options</div>
	<div class="shippingmethod">
		<?php if($shippings):?>
		<fieldset>
		<?php echo $this->Form->input('ProductShippingMethods',array('id'=>'ProductShippingMethod','div'=>false,'label'=>false,'options'=>$shippings,'empty'=>'Select Shipping Method'));?>
		<label style="padding:0 30px 0 10px;">Flat Cost : $<span id="flatcost"><?php echo $this->data['Category']['shipping_cost'];?></span></label><input type="button" class="button" value="Add" name="addflatcost" id="addflatcost">
		</fieldset>
		<div class="shippingmethods shipping-left">
		<div class="search-title">Selected Shipping Methods</div>
		
		<table width="100%" border="0">
			<tr><th width="65%"><b>Shipping Method</b></th>
				<th width="15%"><b>Flat Cost</b></th>
				<th width="15%"><b>Action</b></th>
			</tr>
			<?php 
				if(isset($this->data['ProductShippings'])):
				$i=0;
				foreach($this->data['ProductShippings'] as $ProductShipping):				
					echo"<tr id='row_".$ProductShipping['ProductShipping']['id']."'><td style='border-width:0px;'>".$ProductShipping['Shipping']['shipping_method']."</td><td style='border-width:0px;'>$".$this->data['Category']['shipping_cost']."</td>
					<td style='border-width:0px;'>
					<input type='hidden' class='ProductShippings_".$ProductShipping['ProductShipping']['id']."' name='data[ProductShippings][".$i."][id]' value='".$ProductShipping['ProductShipping']['id']."'>
					<input type='hidden' class='ProductShippings_".$ProductShipping['ProductShipping']['id']."' name='data[ProductShippings][".$i."][product_id]' value='".$ProductShipping['ProductShipping']['product_id']."'>
					<input type='hidden' class='ProductShippings_".$ProductShipping['ProductShipping']['id']."' name='data[ProductShippings][".$i."][shipping_id]' value='".$ProductShipping['ProductShipping']['shipping_id']."'>
					<a href='javascript:void(0);' class='deleteshipping' rowID='".$ProductShipping['ProductShipping']['id']."'>Delete</a></td></tr>";
				$i++;
				endforeach;
				endif;
			?>
		</table>
		<div id="loader_domestic_shipping" style="text-align:left;display:none;"><img alt="Adding shipping methods..." src="<?php echo Configure::read('base_url');?>img/loading.gif">Adding shipping methods...</div>
	</div>

	<div class="handalingtime shipping-right">
		<fieldset>
			<label style="padding:0 20px 0 10px;">Handling Time<em>*</em> :</label>
			<?php echo  $this->Form->input('handletime_id',array('selected'=>$this->data['Product']['handletime_id'],'id'=>'handalingtime','class'=>'required','div'=>false,'label'=>false,'options'=>$handalingtimes,'empty'=>'Select a Handling Time'));?>
		</fieldset>
		<p>Additional info:<br /><span>Max <span id="counter"></span> characters</span></p>		
		<textarea id="HandaleAdditionalInfo" name="data[Product][handale_additional_info]" style="width:740px;height:120px;"><?php echo $this->data['Product']['handale_additional_info'];?></textarea>
	</div>
	<?php else:?>
	<span class="error_text">No shipping method found.</span>
	<?php endif;?>
	</div>
</div>

<div class="select-category">	
	<div class="search-title">8. International shipping</div>
	<fieldset>
	<p id="internationalShippingOption">
	<?php 
		$options=array('Yes'=>'Provide International Shipping','No'=>'International Shipping Not Allowed');
		$attributes=array('legend'=>false,"div"=>false,"label"=>false,"class"=>"btn-radio","style"=>"margin:10px;");
		echo $this->Form->radio('product_international_shipping',$options,$attributes);	
		?>		
	</p>
	</fieldset>	
	<?php $hideform='';
	 if($this->data['Product']['product_international_shipping']=="No"){ 
	 $hideform=' style="display:none;"';
	 }
	 ?>	
	<div class="internationalshipping">
		<table cellspacing="0" width="98%">
			<tr><th width="50%">Shipping Method</th><th width="15%">Location(s)</th><th width="15%">Flat Shipping Cost</th><th width="10%">Action</th></tr>
				<?php 
				//pr($productinternationalshippings);
				if(isset($productinternationalshippings)):
				$i=0;
					foreach($productinternationalshippings as $productinternationalshipping):
						echo'<tr id="rowINT_'.$productinternationalshipping['ProductInternationalShipping']['id'].'">
							<td style="text-align:center;">'.$productinternationalshipping['Shipping']['shipping_method'].'</td>
							<td style="text-align:center;">'.$productinternationalshipping['ProductInternationalShipping']['continent_id'].'</td>
							<td style="text-align:center;">$ '.$productinternationalshipping['ProductInternationalShipping']['shipping_cost'].'</td>
							<td style="text-align:center;">						
								<a href="javascript:void(0);" rowID="'.$productinternationalshipping['ProductInternationalShipping']['id'].'" class="editinternationalshipping">Edit</a>&nbsp;&nbsp;
								<a href="javascript:void(0);" rowID="'.$productinternationalshipping['ProductInternationalShipping']['id'].'" class="deleteinternationalshipping">Delete</a>
							</td>
							</tr>';
						$i++;
				endforeach;
				endif;	
				?>		
		</table>
		<div id="loader_international_shipping" style="text-align:left;display:none;"><img alt="Adding shipping methods..." src="<?php echo Configure::read('base_url');?>img/loading.gif">Adding shipping methods...</div>		
	</div>
	<table id="internationlashippingform" <?php echo $hideform;?>  width="98%">
		<tr>
			<td valign="top" align="right">Shipping Method :</td><td>&nbsp;</td><td valign="top">
			<?php echo $this->Form->input('internationalshippingmethod',array('id'=>'ProductInternationalshippingmethod','div'=>false,'label'=>false,'options'=>$shippings,'empty'=>'Select Shipping Method','style'=>'width:280px;'));?>
			</td><td>&nbsp;</td><td>Flat Shipping Cost : $</td><td><?php echo $this->Form->input('internationalshippingcost',array("div"=>false,"label"=>false,"size"=>10)); ?></td>
		</tr>
		<tr>
			<td valign="top" align="right">&nbsp;Shipping Location :</td><td>&nbsp;</td><td valign="top">
			<?php 
			$internationalocations_custom=$internationalocations;
			$options2['']="Select Shipping Location";				
			$options2=array_merge($options2,$internationalocations);		
			$internationalocations['worldwide']="Worldwide";		
			$internationalocations['custom_location']="Custom Location";		
				
			echo $this->Form->input('internationalshippinglocation',array("div"=>false,"label"=>false,'options' => $internationalocations));
			?></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
		</tr>
		<tr id="custom_location" align="left" style="display:none;">
			<td valign="top" colspan="6">&nbsp;&nbsp;&nbsp;Custom Location :
			<?php
				foreach($internationalocations_custom as $key=>$val):
					echo'<input type="checkbox" name="data[customlocation][]" value="'.$key.'" />&nbsp;'.$val.'&nbsp;';
				endforeach;
			?></td>
		</tr>
		<tr>
			<td valign="top"></td><td>&nbsp;</td><td valign="top">
			</td><td>&nbsp;</td><td>&nbsp;</td><td><input class="button" type="button" name="cancel"  id="cancelInternationaShipping" value="Cancel" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="button" type="button" id="saveInternationaShipping" name="save" value="Save" /></td>
		</tr>
		
	</table>	
	<input type="button" class="button" name="addAnotherShipping" value="Add Another" style="display:none;" />
	<input type="hidden" name="addShippingCounter" id="addShippingCounter" value="0" />
	
	<p style="padding-left:10px;">Additional Info :<br /><span>Max <span id="counter4"></span> characters :</span></p>
	<textarea id="InternationalShippingAdditionalInfo" name="data[Product][international_shipping_additional_info]" style="width:742px;height:120px;margin:10px;"><?php echo $this->data['Product']['international_shipping_additional_info'];?></textarea>
	
</div>
<div class="select-category">
	<div class="search-title">9. Return Policy</div>
        <p>All Sellers must specify a Return Policy, even if the policy is that you do not accept returns. We encourage you to work with Buyers if there are any problems.</p>
	<fieldset style="padding:0 10px;">
	<?php echo $this->Form->input('products_returnPolicyType',array("value"=>"Yes","div"=>false,"label"=>false,"type"=>"checkbox","class"=>"checkBox-position"));?><label>Display global Return Policy for this product</label>
	<p style="width:300px; ">Space left: <span id="returnplicy"></span> of 2000 characters</p>
	<div id="return_policy">
	<?php	
		echo $this->Form->input('products_returnPolicy',array("div"=>false,"label"=>false,"style"=>"width:740px; height:200px; margin:10px 0;","class"=>"fckrequired"));
	?>
<?php echo $fck->load('ProductProductsReturnPolicy', 'Basic');?>
	</div>
	</fieldset>
</div>	
<div class="select-category">
<div class="search-title">10. Additional Options</div>
<fieldset class="add-option">
  <label class="label-add-option">Auto Re-list</label> <p class="check-add-option">
  <?php echo $this->Form->input('auto_re_list',array("div"=>false,"type"=>"checkbox","label"=>false,"value"=>"Yes","class"=>"checkBox-position"));?>
  Yes, enable automatic re-listing of this item after expiry</p>
</fieldset>
<fieldset class="add-option">
	<label class="label-add-option">Block buyers</label>
	<p class="check-add-option">
		<input type="checkbox" id="block_country_check" checked="checked" class="checkBox-position" />
		<?php echo $this->Form->input("block_country",array('id'=>'block_country','type'=>'hidden'));?>
		<a href="javascript:void(0);" ElmID="<?php echo $this->data['Product']['id'];?>" controller="products" action="blockcountry" onclick="showPop(this);">Who are registered in countries to which I don't ship</a>
	</p>
</fieldset>
<fieldset class="add-option">
  <label class="label-add-option">Salse Tax</label> <p class="check-add-option">
<?php echo $this->Form->input('tax_us',array("div"=>false,"type"=>"checkbox","label"=>false,"value"=>"Yes","class"=>"checkBox-position"));?> 
 Sales Tax for US&nbsp;&nbsp;
  
  <a href="javascript:void(0);" controller="salestaxes" action="index" ElmID="<?php echo $this->data['Product']['id'];?>" onclick="showPop(this);">Refer To Sales Tax Table</a></p>
</fieldset>
<fieldset class="add-option">
	<label class="label-add-option">Payment</label>
		<p class="check-add-option">	
			<?php echo $this->Form->input("use_paypal",array("type"=>"checkbox","div"=>false,"label"=>false,"value"=>"Yes","class"=>"checkBox-position"));?>Accept payment through PayPal
			<!--input type="text" name="data[Product][paypal]" value="<?php echo $session->read('Auth.User.paypal');?>" class="checkBox-position" /-->
			<?php //echo $this->Form->input("paypal",array("div"=>false,"label"=>false,"class"=>"checkBox-position"));?>
			<br />
			<?php echo $this->Form->input("use_google_checkout",array("type"=>"checkbox","div"=>false,"label"=>false,"value"=>"Yes","class"=>"checkBox-position"));?>Accept payment through Google Checkout
			<!--input type="text" name="data[Product][google_checkout]" value="<?php echo $session->read('Auth.User.google_checkout');?>" class="checkBox-position" /><br /-->
		</p>
</fieldset>

</div>
	</fieldset>
	<input class="button" type="submit" name="Save" value="Save" />
</form>
</div>
</div>
<?php else:?>
<p><b style="font-size:14px;">Sorry! Product edits are not available due to any of the following reasons:</b>
<ul style="margin-left:50px;">
    <li>You are not the seller</li>
    <li>Item expired</li>
    <li>Product is not available in the system</li>    
</ul>
</p>
<?php endif;?>
<?php  echo $html->script(array("jquery.form.js","jquery.validate.js","jquery.simplyCountable","jquery.autocomplete.js"));?>
<script type="text/javascript">	
jQuery(document).ready(function(){
catid=jQuery("#hiddencatid").val();

jQuery.validator.addMethod("fckrequired", function (value, element) {
        var oEditor = FCKeditorAPI.GetInstance('ProductProductsDescription') ;
        var pageValue = oEditor.GetHTML(true);
        pageValue=jQuery.trim(pageValue);
        if ( pageValue == "<br />" || pageValue == "") {
            return false;
        }else{
            return true;
        }
    }, "This field is required.");

jQuery('#ProductProductsReturnPolicy').simplyCountable({
		counter: '#returnplicy',
        countType: 'characters',
        maxCount: 2000,
        countDirection: 'down'
	});

        jQuery('#ProductProductsDescription').simplyCountable({
		counter: '#counter2',
        countType: 'characters',
        maxCount: 2000,
        countDirection: 'down'
	});

jQuery("#ProductProductsReturnPolicyType").click(function(){
	if(this.checked==true)
		jQuery("#return_policy").fadeIn("250").hide();
	else
		jQuery("#return_policy").fadeOut("250").show();
});
jQuery.validator.addMethod("brandrequired", function (value, element) {
        var pageValue=jQuery("#sugestbrands").val();
        if ( pageValue == "Enter Brand" || pageValue == "") {
            return false;
        }else{
            return true;
        }
    }, "This field is required.");
jQuery.validator.addMethod("stylerequired", function (value, element) {
        var pageValue=jQuery("#sugeststyles").val();
        if ( pageValue == "Enter Style" || pageValue == "") {
            return false;
        }else{
            return true;
        }
    }, "This field is required.");
jQuery.validator.addMethod("conditionrequired", function (value, element) {
        var pageValue=jQuery("#sugestconditions").val();
        if ( pageValue == "Enter Condition" || pageValue == "") {
            return false;
        }else{
            return true;
        }
    }, "This field is required.");
	var v = jQuery("#ProductSellSimilarForm").validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
	jQuery("a.removeanotherimage").live('click',function(){
		var currentTotalImg=jQuery("#totalImage").val();
		var currentImgIndex=parseInt(currentTotalImg)-1;
		jQuery("#totalImage").val(currentImgIndex);
		jQuery(this).parent().remove();
	});
	
	//Load Parent Category
	var url= baseurl+"products/fetchParentCategory/<?php echo $this->data['subcat']['catid_label2'];?>";
	jQuery(".firstlabel").show().fadeIn("slow");
		jQuery(".firstlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Parent Category...");
		jQuery.get(url, function(data) {
			jQuery('.firstlabel').html(data);	
			<?php if($this->data['subcat']['label4']=="No" AND $this->data['subcat']['label3']=="No" AND $this->data['subcat']['label2']=="No"):?>
			loadImages(<?php echo $this->data['subcat']['catid_label2'];?>);	
			<?php if($this->data['Product']['global_brands']>0)?>
			loadBrand(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['global_brands'];?>);
			<?php if($this->data['Product']['global_styles']>0)?>
			loadStyle(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['global_styles'];?>);
			<?php if($this->data['Product']['global_conditions']>0)?>
			loadCondition(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['global_conditions'];?>);	
			loadAdditionalFields(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['id'];?>);
			loadSizes(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['id'];?>);				
			//loadShippingMethod(<?php echo $this->data['subcat']['catid_label2'];?>,<?php echo $this->data['Product']['id'];?>);
			<?php endif;?>
		});
		
	<?php if($this->data['subcat']['label2']=="Yes"):?>
		jQuery(".secondlabel").show().fadeIn("slow");
		jQuery(".secondlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");			
			var sub_url= baseurl+"products/fetchSubCategory/<?php echo $this->data['subcat']['catid_label2']."/".$this->data['subcat']['catid_label3'];?>";
				jQuery.get(sub_url, function(data){
				jQuery('.secondlabel').html(data);	
				<?php if($this->data['subcat']['label4']=="No" AND $this->data['subcat']['label3']=="No"):?>
				loadImages(<?php echo $this->data['subcat']['catid_label3'];?>);	
				<?php if($this->data['Product']['global_brands']>0)?>
				loadBrand(<?php echo $this->data['subcat']['catid_label3'];?>,<?php echo $this->data['Product']['global_brands'];?>);
				<?php if($this->data['Product']['global_styles']>0)?>
				loadStyle(<?php echo $this->data['subcat']['catid_label3'];?>,<?php echo $this->data['Product']['global_styles'];?>);
				<?php if($this->data['Product']['global_conditions']>0)?>
				loadCondition(<?php echo $this->data['subcat']['catid_label3'];?>,<?php echo $this->data['Product']['global_conditions'];?>);					
				loadAdditionalFields(<?php echo $this->data['subcat']['catid_label3'];?>,<?php echo $this->data['Product']['id'];?>);
				loadSizes(<?php echo $this->data['subcat']['catid_label3'];?>,<?php echo $this->data['Product']['id'];?>);				
				loadShippingMethod(<?php echo $this->data['subcat']['catid_label3'];?>);
				<?php endif;?>
				});
	<?php endif;?>
	
	<?php if($this->data['subcat']['label3']=="Yes"):?>
		jQuery(".thirdlabel").show().fadeIn("slow");
		jQuery(".thirdlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");			
			var sub_url= baseurl+"products/fetchSubCategory/<?php echo $this->data['subcat']['catid_label3']."/".$this->data['subcat']['catid_label4'];?>";
				jQuery.get(sub_url, function(data) {
				jQuery('.thirdlabel').html(data);
				<?php if($this->data['subcat']['label4']=="No"):?>
				loadImages(<?php echo $this->data['subcat']['catid_label4'];?>);	
				<?php if($this->data['Product']['global_brands']>0)?>
				loadBrand(<?php echo $this->data['subcat']['catid_label4'];?>,<?php echo $this->data['Product']['global_brands'];?>);
				<?php if($this->data['Product']['global_styles']>0)?>
				loadStyle(<?php echo $this->data['subcat']['catid_label4'];?>,<?php echo $this->data['Product']['global_styles'];?>);
				<?php if($this->data['Product']['global_conditions']>0)?>
				loadCondition(<?php echo $this->data['subcat']['catid_label4'];?>,<?php echo $this->data['Product']['global_conditions'];?>);					
				loadAdditionalFields(<?php echo $this->data['subcat']['catid_label4'];?>,<?php echo $this->data['Product']['id'];?>);
				loadSizes(<?php echo $this->data['subcat']['catid_label4'];?>,<?php echo $this->data['Product']['id'];?>);				
				loadShippingMethod(<?php echo $this->data['subcat']['catid_label4'];?>);
				<?php endif;?>				
				});
	<?php endif;?>
	
	<?php if($this->data['subcat']['label4']=="Yes"):?>
		jQuery(".fourthlabel").show().fadeIn("slow");
		jQuery(".fourthlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");			
			var sub_url= baseurl+"products/fetchSubCategory/<?php echo $this->data['subcat']['catid_label4']."/".$this->data['subcat']['catid_label5'];?>";
				jQuery.get(sub_url, function(data) {
				jQuery('.fourthlabel').html(data);	
				loadImages(<?php echo $this->data['subcat']['catid_label5'];?>);	
				<?php if($this->data['Product']['global_brands']>0)?>
				loadBrand(<?php echo $this->data['subcat']['catid_label5'];?>,<?php echo $this->data['Product']['global_brands'];?>);
				<?php if($this->data['Product']['global_styles']>0)?>
				loadStyle(<?php echo $this->data['subcat']['catid_label5'];?>,<?php echo $this->data['Product']['global_styles'];?>);
				<?php if($this->data['Product']['global_conditions']>0)?>
				loadCondition(<?php echo $this->data['subcat']['catid_label5'];?>,<?php echo $this->data['Product']['global_conditions'];?>);
				loadAdditionalFields(<?php echo $this->data['subcat']['catid_label5'];?>,<?php echo $this->data['Product']['id'];?>);
				loadSizes(<?php echo $this->data['subcat']['catid_label5'];?>,<?php echo $this->data['Product']['id'];?>);				
				loadShippingMethod(<?php echo $this->data['subcat']['catid_label5'];?>);
				});
	<?php endif;?>
	
	//Add Another Image
	jQuery("input[id=addAnotherImage]").live('click',function(){
		var currentTotalImg=jQuery("#totalImage").val();
		if(currentTotalImg<=15){
			var currentImgIndex=parseInt(currentTotalImg);
			var html='<span id="span_'+currentImgIndex+'">Image '+currentImgIndex+' <input type="file" class="validatefiletype" id="ProductFileName'+currentImgIndex+'" name="data[Product][fileName'+currentImgIndex+']" /><input type="hidden" value="No" name="data[ProductImage]['+currentImgIndex+'][required]" />&nbsp;<a href="javascript:void(0);" class="removeanotherimage"><img alt="delete image" src="'+baseurl+'img/icoerror.png"></a><br /></span>';
			var currentImgIndex=parseInt(currentTotalImg)+1;
			jQuery("#totalImage").val(currentImgIndex);
			jQuery(html).insertBefore(jQuery(this));
		}		
	});
	
	jQuery("#ProductCategoryId").live('click',function(){		
		
		var url= baseurl+"products/fetchSubCategory/"+this.value;	
		jQuery("#hiddencatid").val(this.value);
                catid=this.value;
		var breadcrumb="";
		
		//Load Second label Sub category
		if(jQuery(this).parent().next().hasClass('secondlabel')){
			breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+"</span></p>";			
			jQuery(".fourthlabel").hide().fadeOut("slow");
			jQuery(".thirdlabel").hide().fadeOut("slow");
			jQuery(".secondlabel").show().fadeIn("slow");
			//Load Sub category
			jQuery(".secondlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");			
			
				jQuery.get(url, function(data) {
				jQuery('.secondlabel').html(data);		  
				});
			loadImages(this.value);	
			//loadBrand(this.value,"");
			//loadStyle(this.value,"");
			//loadCondition(this.value,"");
			loadAdditionalFields(this.value,<?php echo $this->data['Product']['id'];?>);			
			loadSizes(this.value,<?php echo $this->data['Product']['id'];?>);
			loadShippingMethod(this.value);
		}
	
		//Load Third label Sub category
		if(jQuery(this).parent().hasClass('secondlabel'))
		{
			jQuery("#hiddencatid").val(this.value);
                        catid=jQuery("#hiddencatid").val();
                        jQuery(".fourthlabel").hide().fadeOut("slow");
			jQuery(".thirdlabel").hide().fadeOut("slow");			
			
			jQuery(".thirdlabel").show().fadeIn("slow");			
			if(this.value==0){return false;}
				breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+"</span></p>";
				jQuery(".thirdlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");
				jQuery.get(url, function(data) {
				jQuery('.thirdlabel').html(data);		  
				});
				loadImages(this.value);	
				loadBrand(this.value,"");
				loadStyle(this.value,"");
				loadCondition(this.value,"");	
				loadAdditionalFields(this.value,<?php echo $this->data['Product']['id'];?>);
				loadSizes(this.value,<?php echo $this->data['Product']['id'];?>);				
				loadShippingMethod(this.value);
		}
		
		//Load Fourth label Sub category
		if(jQuery(this).parent().hasClass('thirdlabel'))
		{			
			jQuery("#hiddencatid").val(this.value);
                        catid=jQuery("#hiddencatid").val();
                        jQuery(".fourthlabel").show().fadeIn("slow");
			if(this.value==0){return false;}
				breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+" >> "+jQuery(".thirdlabel select option:selected").text()+"</span></p>";
				jQuery(".fourthlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory for selected Category...");
				jQuery.get(url, function(data) {
				jQuery('.fourthlabel').html(data);		  
				});
				loadImages(this.value);	
				loadBrand(this.value,"");
				loadStyle(this.value,"");
				loadCondition(this.value,"");
				loadAdditionalFields(this.value,<?php echo $this->data['Product']['id'];?>);
				loadSizes(this.value,<?php echo $this->data['Product']['id'];?>);
				loadShippingMethod(this.value);
		}
		
		//Load Fourth label Sub category
		if(jQuery(this).parent().hasClass('fourthlabel'))
		{
			if(this.value==0){return false;}
				breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+" >> "+jQuery(".thirdlabel select option:selected").text()+" >> "+jQuery(".fourthlabel select option:selected").text()+"</span></p>";			
			jQuery("#hiddencatid").val(this.value);
                        catid=jQuery("#hiddencatid").val();
                        loadImages(this.value);
			//loadBrand(this.value,"");
			//loadStyle(this.value,"");
			//loadCondition(this.value,"");
			loadAdditionalFields(this.value,<?php echo $this->data['Product']['id'];?>);
			loadSizes(this.value,<?php echo $this->data['Product']['id'];?>);			
			loadShippingMethod(this.value);
		}
		
		//Generate breadcrumb
		jQuery('.breadcrumb').html(breadcrumb);			
	});

        jQuery('#autobrand').keyup(function() {
                  jQuery('#autoComplete1').val('');
            });
            jQuery('#autostyle').keyup(function() {
                  jQuery('#autostyle1').val('');
            });
            jQuery('#autocondition').keyup(function() {
                  jQuery('#autocondition1').val('');
            });

jQuery("#autobrand").autocomplete(baseurl+"/products/autobrand/"+catid+'/brand',
{
delay:10,
minChars: 1,
cacheLength: 1,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem: formatItem,
 autoFill: false
 });

 jQuery("#autostyle").autocomplete(baseurl+"/products/autobrand/"+catid+'/style',
{
delay:10,
minChars: 1,
cacheLength: 1,
onItemSelect:selectItemst,
onFindValue:findValuest,
formatItem: formatItem,
 autoFill: false
 });

 jQuery("#autocondition").autocomplete(baseurl+"/products/autobrand/"+catid+'/condition',
{
delay:10,
minChars: 1,
cacheLength: 1,
onItemSelect:selectItemcon,
onFindValue:findValuecon,
formatItem: formatItem,
 autoFill: false
 });

    function selectItem(li) {
        findValue(li);
    }

    function findValue(li) {
        //console.log(li)

    // if coming from an AJAX call, let's use the product id as the value
        if( !!li.extra ) var sValue = li.extra[0];
    else
        var sValue = li.selectValue;
    jQuery('#autoComplete1').val(sValue);
   // alert("The value you selected was: " + sValue);
    }

     function selectItemst(li) {
        findValuest(li);
    }

    function findValuest(li) {
        //console.log(li)

    // if coming from an AJAX call, let's use the product id as the value
        if( !!li.extra ) var sValue = li.extra[0];
    else
        var sValue = li.selectValue;
    jQuery('#autostyle1').val(sValue);
   // alert("The value you selected was: " + sValue);
    }

     function selectItemcon(li) {
        findValuecon(li);
    }

    function findValuecon(li) {
        //console.log(li)

    // if coming from an AJAX call, let's use the product id as the value
        if( !!li.extra ) var sValue = li.extra[0];
    else
        var sValue = li.selectValue;
    jQuery('#autocondition1').val(sValue);
   // alert("The value you selected was: " + sValue);
    }

    function formatItem(row) {
        if(row[1] == undefined) {
            return row[0];
        }
        else {
            return row[0];
            //return row[0] + " (id: " + row[1] + ")";
        }
    }
	
	jQuery("#ProductGlobalBrand").live('change',function(){
		if(this.value=="addanother"){
			html='<input id="sugestbrands" class="brandrequired" type="input" name="data[Product][sugestbrands]" value="Enter Brand" onblur="';
			html+="if(this.value=='') this.value='Enter Brand'";
			html+='"';
			html+='onfocus="if(this.value==';
			html+="'Enter Brand') this.value='';";
			html+='"><input type="hidden" name="data[Brand][global]" value="No">';
			jQuery(this).hide();	
			jQuery(this).after(html);
		}	
	});
	
	jQuery("#ProductGlobalStyle").live('change',function(){
		if(this.value=="addanother"){
			html='<input id="sugeststyles" class="stylerequired" type="input" name="data[Product][sugeststyles]" value="Enter Style" onblur="';
			html+="if(this.value=='') this.value='Enter Style'";
			html+='"';
			html+='onfocus="if(this.value==';
			html+="'Enter Style') this.value='';";
			html+='"><input type="hidden" name="data[Brand][global]" value="No">';
			jQuery(this).hide();	
			jQuery(this).after(html);
		}	
	});
	
	jQuery("#ProductGlobalCondition").live('change',function(){
		if(this.value=="addanother"){
			html='<input id="sugestconditions" class="conditionrequired" type="input" name="data[Product][sugestconditions]" value="Enter Condition" onblur="';
			html+="if(this.value=='') this.value='Enter Condition'";
			html+='"';
			html+='onfocus="if(this.value==';
			html+="'Enter Condition') this.value='';";
			html+='"><input type="hidden" name="data[Brand][global]" value="No">';
			jQuery(this).hide();	
			jQuery(this).after(html);
		}	
	});
	
	jQuery('input[id=addflatcost]').live('click',function(){
		var shipID=jQuery("select#ProductShippingMethod").val();
		var shipCOST=jQuery("#flatcost").html();		
		err_msg="";
		if(shipID=="")
		err_msg+="You have to select a shipping method.";
		if(shipCOST=="0.00")
		err_msg+="\n\nShipping cost can not be $0.00. Please select a category.";
		if(err_msg==""){
			jQuery("#loader_domestic_shipping").show();
		jQuery.ajax({
					type: 'GET',
					url: baseurl+"products/getshippingmethods/"+shipID,					
					dataType: 'json',
					success: function(data){
						var addRow=false;
						jQuery('.shippingmethods table td').each(function(index) {							
							if(data.shipping_method==jQuery(this).text()){
								addRow=true;
								return false;
							}
						});
						if(addRow){
							jQuery("#loader_domestic_shipping").hide();
							alert("You already add this shipping method.");return false;						
						}else{
							jQuery("#loader_domestic_shipping").hide();
							jQuery(".shippingmethods table").append("<tr id='row_"+data.id+"'><td style='border-width:0px;'>"+data.shipping_method+"</td><td style='border-width:0px;'>$"+shipCOST+"</td><td style='border-width:0px;'><a href='javascript:void(0);' class='deleteshipping' rowID='"+data.id+"'>Delete</a></td></tr>");						
							//jQuery("#flatcost").html("0.00");
							jQuery("select#ProductShippingMethod").val("0");						
							jQuery(".shippingmethods").append("<input type='hidden' class='ProductShippings_"+data.id+"' name='data[ProductShippings]["+data.id+"][shipping_id]' value='"+data.id+"'>");
							return false;
						}
					}			
			});
			}else{alert(err_msg);}	
	}); 
	
	//Domestic Shipping
	jQuery('tr td a.deleteshipping').live('click',function(){
		var rowID=jQuery(this).attr("rowID");
		jQuery.ajax({
					type: 'GET',
					url: baseurl+"products/deleteshippingmethods/"+rowID,					
					dataType: 'json',
					success: function(data){
						jQuery('#row_'+data.RowId).remove();			
						jQuery(".ProductShippings_"+data.RowId).remove();
					}
				});	
	});
	
	//International Shipping
	jQuery('tr td a.deleteinternationalshipping').live('click',function(){
		var rowID=jQuery(this).attr("rowID");
		if(confirm("Are you sure you want to remove this shipping method from this product?"))
		{
			jQuery.ajax({
					type: 'GET',
					url: baseurl+"products/deleteinternationalshippingmethods/"+rowID,					
					dataType: 'json',
					success: function(data){
						jQuery('#rowINT_'+data.RowId).remove();
						jQuery(".ProductInternationalShippings_"+data.RowId).remove();
					}
				});			
		}	
		else return false;	
		
	});
	jQuery("#saveInternationaShipping").click(function(){
		var err="";
		var PIS=jQuery("#ProductInternationalshippingmethod").val();
		if(PIS=="")
			err+="Please select a Shipping Method.\n";
		else
			var PIS_label=jQuery("#ProductInternationalshippingmethod option:selected").text();
			
			
			
		var PISC=jQuery("#ProductInternationalshippingcost").val();		
		
		if(PISC=="" || PISC=="0.00")
			err+="Please enter a valid Shipping Cost\n";
		
		var PISL=jQuery("#ProductInternationalshippinglocation").val();		
		if(PISL=="" || PISL==null)
			err+="Please select a Shipping Location.\n";		
		else		
			{				
				var PISL_label=jQuery("#ProductInternationalshippinglocation option:selected").text();
			}
        if(err!="")	
			alert(err);		
		else{
			jQuery("#loader_international_shipping").show();
			var i=jQuery("#addShippingCounter").val();						
			jQuery("#ProductInternationalshippingcost").html("0.00");
			jQuery("select#ProductInternationalshippingmethod").val("0");						
			
			jQuery(".internationalshipping table").append("<tr id='rowINT_"+i+"'><td style='text-align:center;'>"+PIS_label+"</td><td style='text-align:center;'>"+PISL_label+"</td><td style='text-align:center;'>$ "+PISC+"</td><td style='text-align:center;'><a href='javascript:void(0);' rowID='"+i+"' class='deleteinternationalshipping'>Delete</a></td></tr>");						
			jQuery(".internationalshipping").append("<input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][shipping_id]' value='"+PIS+"'><input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][continent_id]' value='"+PISL+"'><input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][shipping_cost]' value='"+PISC+"'>");
			
			i=parseInt(i)+1;			
			jQuery("#addShippingCounter").val(i);
			jQuery("#loader_international_shipping").hide();
			return false;
		}	
	});
	
	jQuery('#ProductProductsDescription').simplyCountable({
		counter: '#counter2',
        countType: 'characters',
        maxCount: 2000,
        countDirection: 'down'
	});
	jQuery('#ProductProductsReturnPolicy').simplyCountable({
		counter: '#counter3',
        countType: 'characters',
        maxCount: 2000,
        countDirection: 'down'
	});
	jQuery('#InternationalShippingAdditionalInfo').simplyCountable({
		counter: '#counter4',
        countType: 'characters',
        maxCount: 1000,
        countDirection: 'down'
	});
	jQuery('#HandaleAdditionalInfo').simplyCountable({
		counter: '#counter',
        countType: 'characters',
        maxCount: 1000,
        countDirection: 'down'
	});
	jQuery('#Product_remove_thumb').live('click',function(){
		html='<input class="validatefiletype" type="file" id="ProductFileName" name="data[Product][fileName]">';
		if(this.checked==true)
			jQuery("#thumbImage").append(html);
		else
		jQuery("#ProductFileName").remove();
	});
	
	jQuery('#addanotherimage input[type=checkbox]').live('click',function(){
		var imgID=jQuery(this).attr('imgID');
		var imgPOS=jQuery(this).attr('imgPOS');
		html='<input type="file" id="ProductFileName'+imgPOS+'" class="required validatefiletype" name="data[Product][fileName'+imgPOS+']" /><input type="hidden" id="ProductFileNameHidden'+imgPOS+'" value="'+imgID+'" name="data[ProductImage]['+imgPOS+'][id]" />';
		
		if(this.checked==true){
			jQuery(this).after(html);
		}else{
			jQuery("#ProductFileNameHidden"+imgPOS).remove();
			jQuery("#ProductFileName"+imgPOS).remove();
		}
	});
	jQuery('p#internationalShippingOption input[type=radio]').click(function(){
		var shippFlag=jQuery(this).val();
		if(shippFlag=="Yes")
		jQuery("#internationlashippingform").fadeIn("250").show();
		else{
			jQuery("input[name=addAnotherShipping]").fadeOut("250").hide();
			jQuery("#internationlashippingform").fadeIn("250").hide();
		}	
	});
	
	jQuery('input[name=addAnotherShipping]').click(function(){
		jQuery("input[name=addAnotherShipping]").fadeOut("250").hide();	
		jQuery("#internationlashippingform").fadeIn("250").show();		
	});
	jQuery('#cancelInternationaShipping').click(function(){		
		jQuery("input[name=addAnotherShipping]").fadeIn("250").show();
		jQuery("#internationlashippingform").fadeOut("250").hide();		
	});
	jQuery("#ProductInternationalshippinglocation").change(function(){
		var PISL_val=jQuery(this).val();
		if	(PISL_val=="worldwide"){
			jQuery("#custom_location").fadeOut().hide("250");
		}
		else if(PISL_val=="custom_location"){			
			jQuery("#custom_location").fadeIn("250").show();
		}
		else{ 
			jQuery("#custom_location").fadeOut("250").hide("250");
		}
	});
	/*jQuery(".AdditionalFields select").live('change',function(){
		if(this.value=="Others"){
			var fieldName=this.name+"[Others]";
			html='<input type="input" name="'+fieldName+'" value="" />'; 			
			jQuery(this).hide();	
			jQuery(this).after(html);
		}	
	});*/
	jQuery("select#sizearray").live('change',function(){
		
		if(this.value!=""){
			//var );	
			var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
			//alert(brandurl);
			jQuery.get(brandurl, function(data) {
			jQuery('select#valuearray').html(data);		  
			});
		}else{
			return false;
		}		
	});
	jQuery("select#sizearray0").live('change',function(){
		
		if(this.value!=""){
			//var );	
			var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
			//alert(brandurl);
			jQuery.get(brandurl, function(data) {
			jQuery('select#valuearray0').html(data);
			});
		}else{
			return false;
		}		
	});
	jQuery("select#sizearray1").live('change',function(){
		
		if(this.value!=""){
			//var );	
			var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
			//alert(brandurl);
			jQuery.get(brandurl, function(data) {
			jQuery('select#valuearray1').html(data);				
			});
		}else{
			return false;
		}		
	});
	jQuery("select#sizearray2").live('change',function(){
		
		if(this.value!=""){
			//var );	
			var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
			//alert(brandurl);
			jQuery.get(brandurl, function(data) {
			jQuery('select#valuearray2').html(data);				
			});
		}else{
			return false;
		}		
	});
	jQuery("select#sizearray3").live('change',function(){
		
		if(this.value!=""){
			//var );	
			var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
			//alert(brandurl);
			jQuery.get(brandurl, function(data) {
			jQuery('select#valuearray3').html(data);				
			});
		}else{
			return false;
		}		
	});
	jQuery("#ProductLowerprice").click(function(){		
		if(jQuery(this).attr("checked")==true){
		jQuery("#ProductProductsOfferDeclineLowerPrice").removeAttr("disabled");
		jQuery("#ProductProductsOfferDeclineLowerPrice").addClass("required");
		}
		else{
		jQuery("#ProductProductsOfferDeclineLowerPrice").attr("disabled","disabled");
		jQuery("#ProductProductsOfferDeclineLowerPrice").removeClass("required");
		}
	});
	jQuery("#ProductLeastprice").click(function(){
		if(jQuery(this).attr("checked")==true){
			jQuery("#ProductProductsOfferAcceptLeastPrice").removeAttr("disabled");
			jQuery("#ProductProductsOfferAcceptLeastPrice").addClass("required");
			}
		else{	
			jQuery("#ProductProductsOfferAcceptLeastPrice").attr("disabled","disabled");
			jQuery("#ProductProductsOfferAcceptLeastPrice").removeClass("required");
			}
	});
	jQuery(".other_addfield").live('keyup',function(){
		fieldvalue=jQuery(this).val();
		fieldID=jQuery(this).attr("fieldID");
		jQuery('.fiels_label_'+fieldID).html('<img alt="Checking duplicate dropdown value" src="'+baseurl+'/img/loading.gif">');
		jQuery.ajax({
			type: 'GET',
			url: baseurl+"products/chkduplicatefield/"+fieldID+"/"+fieldvalue,					
			dataType: 'json',
			success: function(data){
				jQuery('.fiels_label_'+data.fid).html(data.message);
			}			
		});
	}); 
});
function loadImages(Id){
		//Load Global brands for this category
			jQuery("#addanotherimage").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Images field...");
			var brandurl=baseurl+"products/fetchimages/"+Id;
			jQuery.get(brandurl, function(data) {
			jQuery('#addanotherimage').html(data);		  
			});
		}		
		function loadBrand(Id,Id2){
		//Load Global brands for this category
			jQuery(".GlobalBrands").show().fadeIn("slow");
			jQuery(".GlobalBrands").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global brands for selected category...");
			var brandurl=baseurl+"products/fetchbrand/"+Id+"/"+Id2;
			jQuery.get(brandurl, function(data) {
			jQuery('.GlobalBrands').html(data);		  
			});
		}	
		
		function loadStyle(Id,Id2){
			//Load Global styles for this category
			jQuery(".GlobalStyles").show().fadeIn("slow");
			jQuery(".GlobalStyles").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global styles for selected category...");
			var brandurl=baseurl+"products/fetchstyle/"+Id+"/"+Id2;
			jQuery.get(brandurl, function(data) {
			jQuery('.GlobalStyles').html(data);		  
			});
		}	
		
		function loadCondition(Id,Id2){
			//Load Global conditions for this category
			jQuery(".GlobalConditions").show().fadeIn("slow");
			jQuery(".GlobalConditions").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global conditions for selected category...");
			var brandurl=baseurl+"products/fetchcondition/"+Id+"/"+Id2;
			jQuery.get(brandurl, function(data) {
			jQuery('.GlobalConditions').html(data);		  
			});
		}
		function loadAdditionalFields(Id,Id2){
			//Load additional fields for this category			
			jQuery(".AdditionalFields").show().fadeIn("slow");
			jQuery(".AdditionalFields").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Additional fields for selected category...");
			var brandurl=baseurl+"products/fetchadditionalfields/"+Id+"/"+Id2;
			jQuery.get(brandurl, function(data) {
			jQuery('.AdditionalFields').html(data);		  
			});
		}		
		function loadSizes(Id,Id2){
			//Load size title and value for this category
			jQuery(".Sizes").show().fadeIn("slow");
			jQuery(".Sizes").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading size information for selected category...");
			var brandurl=baseurl+"products/fetchsizes_edit/"+Id+"/"+Id2;
			jQuery.get(brandurl, function(data) {
			jQuery('.Sizes').html(data);		  
			});
		}
		function loadShippingMethod(Id){
			//Load shipping method for this category			
			jQuery.ajax({
					type: 'GET',
					url: baseurl+"products/getshippingcost/"+Id,					
					dataType: 'json',
					success: function(data){
						jQuery("#flatcost").html(data.shipping_cost);						
						return false;
					}			
			});
		}

function strip_tags(html){

		//PROCESS STRING
		if(arguments.length < 3) {
			html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
		} else {
			var allowed = arguments[1];
			var specified = eval("["+arguments[2]+"]");
			if(allowed){
				var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
				html=html.replace(new RegExp(regex, 'gi'), '');
			} else{
				var regex='</?(' + specified.join('|') + ')\b[^>]*>';
				html=html.replace(new RegExp(regex, 'gi'), '');
			}
		}

		//CHANGE NAME TO CLEAN JUST BECAUSE
		var clean_string = html;

		//RETURN THE CLEAN STRING
		return clean_string;
	}

function FCKeditor_OnComplete(editorInstance) {
		editorInstance.Events.AttachEvent('OnSelectionChange', counterword);
		editorInstance.Events.AttachEvent('OnSelectionChange', counterworddes);
   }

function counterword(){
   var oEditor = FCKeditorAPI.GetInstance('ProductProductsReturnPolicy') ;
   var pageValue = oEditor.GetHTML(true);
   var hh=strip_tags(pageValue);
   var leth=hh.length;
   var remain=(2000-leth);
   if(remain<0){
	   remain=0;
   }
   document.getElementById('returnplicy').innerHTML = remain;
}

function counterworddes(){
   var oEditor = FCKeditorAPI.GetInstance('ProductProductsDescription') ;
   var pageValue = oEditor.GetHTML(true);
   var hh=strip_tags(pageValue);
   var leth=hh.length;
   var remain=(2000-leth);
   if(remain<0){
	   remain=0;
   }
   document.getElementById('counter2').innerHTML = remain;
}
function Othervalue(fid,selectvalue){
	if(selectvalue=="Other" || selectvalue=="Others" || selectvalue=="other" || selectvalue=="others")
	{
		jQuery("#other_"+fid).show().fadeIn("250");
	}else{
		jQuery("#other_"+fid).hide().fadeOut("250");
	}
}
</script>
<style type="text/css">
.selectcatstyle{float:left;}
.hideContent{display:none;}
td{border:0;}
</style>
<?php echo $this->Html->css(array('jquery.autocomplete'));?>